<!-- 成交结算标准 -->
<template>
    <div class="marketSettlementStandard">
        <div>
            创建时间：
            <el-date-picker
                    v-model="searchTime"
                    type="daterange"
                    align="right"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :picker-options="pickerOptions">
            </el-date-picker>
            <el-button type="primary" @click="searchDataByTime" id="monitorEnter">查询</el-button>
            <el-button type="primary" @click="newPage('new',false)">新建</el-button>
        </div>
        <el-table
                :data="tableData"
                highlight-current-row
                style="width: 100%;margin-top: 20px;">
            <el-table-column
                    type="index"
                    label="序号"
                    align="center"
                    width="50">
            </el-table-column>
            <el-table-column
                    property="version"
                    align="center"
                    label="版本号">
            </el-table-column>
            <el-table-column
                    property="extractCategory"
                    align="center"
                    label="提取规则"
                    width="120">
                <template slot-scope="scope">
                    {{extractCategory[scope.row.extractCategory]}}
                </template>
            </el-table-column>
            <el-table-column
                    property="calculationNode"
                    align="center"
                    label="计提节点">
                <template slot-scope="scope">
                    {{scope.row.calculationNodeList | calNodeFilter}}
                </template>
            </el-table-column>
            <el-table-column
                    property="address"
                    align="center"
                    label="计提基数">
                <template slot-scope="scope">
                    {{extractBaseNum[scope.row.extractBaseNum]}}
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    label="区间标准">
                <template slot-scope="scope">
                    <el-button type="text" @click="viewInterval(scope.row.id)">查看</el-button>
                </template>
            </el-table-column>
            <el-table-column
                    align="center"
                    property="createTime"
                    label="创建时间">
            </el-table-column>
            <el-table-column
                    align="center"
                    property="creatorName"
                    label="创建人">
            </el-table-column>
            <el-table-column
                    width="100"
                    align="center"
                    label="详细信息">
                <template slot-scope="scope">
                    <el-button type="text" @click="newPage('view',scope.row.id)">查看</el-button>
                    <el-button type="text" @click="newPage('edit', scope.row.id)">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagebar">
            <el-pagination
                    background
                    layout="total, sizes, prev, pager, next, jumper"
                    :current-page.sync="tableConfig.pageNum"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="tableConfig.pageSize"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :total="tableConfig.totalSize">
            </el-pagination>
        </div>

        <!-- 区间范围弹框 -->
        <el-dialog
                title="查看区间标准"
                :visible.sync="intervalDialogVisible"
                width="50%">
            <div>
                选择分类：
                <el-select v-model="classification" placeholder="请选择等级">
                    <el-option :key="0" label="普通" :value="0"></el-option>
                    <el-option :key="1" label="包销" :value="1"></el-option>
                </el-select>
                <el-table
                        :data="classificationTableData[classification]"
                        border
                        highlight-current-row
                        style="width: 600px;margin-top: 20px;">
                    <el-table-column
                            property="content"
                            align="center"
                            label="计提区间">
                    </el-table-column>
                    <el-table-column
                            align="center"
                            property="calculateExtractProportion"
                            width="150"
                            label="计提比例（%）">
                    </el-table-column>
                </el-table>
            </div>
            <!--<span slot="footer">
                <el-button @click="intervalDialogVisible = false">关闭</el-button>
            </span>-->
        </el-dialog>
    </div>
</template>

<script>
    import api from '@/api/apiPath'
    import {extractCategory, ruleEffect, calNode, extractBaseNum} from '../fieldMap'

    export default {
        name: "marketSettlementStandard",
        title: '市场结算标准',
        data() {
            return {
                currentDealId: 0,
                tableConfig: {
                    startTime: "",
                    endTime: "",
                    pageNum: 1,
                    pageSize: 10,
                    totalSize: 10
                },
                searchTime: [],
                classification: 0,
                classificationTableData: [[], []],
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                intervalDialogVisible: false,
                tableData: [],

                extractCategory,
                ruleEffect,
                calNode,
                extractBaseNum
            }
        },
        created() {
            this.getTransactionSettlementList()
            //this.getAllProjectLevel()
        },
        mounted() {

        },
        activated() {
            this.searchDataByTime();
        },
        filters: {
            calNodeFilter(list) {
                let arr = [];
                list.forEach((item) => {
                    arr.push(calNode[item.calculateNode] + '-' + item.calculateProportion + '%')
                });
                return arr.join(';')
            }
        },
        methods: {
            searchDataByTime() {
                if (this.searchTime === null) {
                    this.searchTime = ["", ""]
                }
                if (this.searchTime.length) {
                    this.tableConfig.startTime = +new Date(this.searchTime[0])
                    this.tableConfig.endTime = +new Date(this.searchTime[1])
                }
                this.tableConfig.pageNum = 1;
                this.getTransactionSettlementList();
            },
            getTransactionSettlementList() {
                this.axios.post(api.marketSettlementStandardGetList, {
                    pageSize: this.tableConfig.pageSize,
                    pageNum: this.tableConfig.pageNum,
                    strDate: this.tableConfig.startTime,
                    endDate: this.tableConfig.endTime,
                }).then((res) => {
                    if (res) {
                        this.tableData = res.data.data.data;
                        this.tableConfig.totalSize = res.data.data.total
                    }
                })
            },
            handleSizeChange(size) {
                this.tableConfig.pageSize = size
                this.getTransactionSettlementList()
            },
            handleCurrentChange(page) {
                this.tableConfig.pageNum = page
                this.getTransactionSettlementList()
            },
            newPage(type, id) {
                this.$router.push({path: "./marketSettlementStandardHandle", query: {type: type, id: id}})
            },
            viewInterval(id) {
                this.currentDealId = id;
                this.classificationTableData = [];
                this.axios.post(api.marketSettlementStandardGetById, {
                    id: id
                }).then((res) => {
                    //console.log(res);

                    this.classification = 0;
                    this.classificationTableData = [[], []]
                    res.data.data.detailVos.forEach((item) => {
                        this.classificationTableData[item.labelType - 1].push(item)
                    })
                    this.intervalDialogVisible = true;
                    //this.classificationOptions = res.data.data;
                    //this.classification = this.classificationOptions[0].projectLevelId;
                    //this.intervalDialogVisible = true;
                    //this.getSingleTSLevel(this.classification, id);
                })
            },
            getSingleTSLevel(projectLevelId, dealId) {
                this.axios.post(api.getSingleTSLevel, {
                    dealId: dealId,
                    projectLevelId: projectLevelId
                }).then((res) => {
                    this.classificationTableData = res.data.data;
                })
            },
        },
        components: {},
        computed: {}
    }
</script>

<style scoped>

</style>
